home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: HELP. How to convert '0x12' into FF char?
- Date: Sun, 24 Mar 96 22:45:25 GMT
- Organization: none
- Message-ID: <827707525snz@genesis.demon.co.uk>
- References: <4iissm$s76@nntp.ucs.ubc.ca> <17MAR199623533662@erich.triumf.ca> <827344614snz@genesis.demon.co.uk> <AD76C75896683B250@mcdialb11.it.luc.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <AD76C75896683B250@mcdialb11.it.luc.edu>
- VArase@varase.it.luc.edu "Verne Arase" writes:
-
- >In article <827344614snz@genesis.demon.co.uk>,
- >Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
- >
- > >>>f='0x';
- > >>>strcpy(f,d);
- > >>>strcpy(f,e);
- > >>>
- > >>>f now contains the string '0x12' right?
- > >>
- > >>No.
- > >
- > >Indeed, it isn't even legal code.
- >
- >Well, it's probably not legal (or at least suffers from suspicious pointer
- >conversion).
-
- There is no conversion since a C compiler is not allowed to convert implicitly
- from an int to a pointer unless it is converting an integral constant
- expression with the value 0 (which becomes a null pointer of the target type).
- The code requires a diagnostic (if string.h was included) and the chances are
- that the compiler won't even generate an execuatble.
-
- >What this would probably end up doing is copying characters until the first
- >NUL charcter is found from absolute memory location 0x00000032 (if ASCII)
- >or 0x000000F1 (if EBCDIC).
-
- If there isn't an executable it can't even do that.
-
- > >>but if you have:
- > >> char f[10] = "0x";
- > >> char d[2] = "1";
- > >> char e[2] = "2";
- > >> strcpy(f,d);
- > >> strcpy(f,e);
- > >
- > >I assume you mean strcat() here.
- >
- >strcat(), like strcpy(), works with character _pointers.
-
- Which are precisely what this code passes to it. But in order to build the
- string "0x12" you need to call strcat() instead of strcpy().
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-